package com.ntschy.taizhou.threaddemo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.*;

// 利用线程池，执行多个任务，并且带有结果。
public class FutureTest4 {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        long startTime = System.currentTimeMillis();
        ExecutorService threadPool = new ThreadPoolExecutor(10, 55, 1, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>());

        List<AlterCheckThread> threads = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            threads.add(new AlterCheckThread(String.valueOf(i), "33" ));
        }
        List<Future<Map<String, List<HashMap>>>> features = threadPool.invokeAll(threads);
        for (Future<Map<String, List<HashMap>>> feature : features) {
            Map<String, List<HashMap>> stringListMap = feature.get();
            System.out.println(stringListMap);
        }
        threadPool.shutdown();
        System.out.println("总共用时" + (System.currentTimeMillis() - startTime) + "ms");
    }

}
